<%@language=vbscript%>
<!--#include file="..\..\CheckSession.inc"-->
<!--#include file="..\..\RootContent.inc"-->
<%	IDFlow=request("IDFlow")
	Nguoitao=request("Nguoitao")
	Filename=Request("Filename")
	UName=Request("Username")
	Hanxuly=Request("Hanxuly")
	MaCB=Request("MaCB")
	Tentep=Request("Tentep")
	Maflow=Request("Maflow")
	bMaRoot=Request("bMaRoot")
	Yeucau=Request("Yeucau")
	bDatao=Request("bDatao")

	Set ClsFun=server.CreateObject("Vinalines.ClsFunction")
	Backform=Request("Backform")
	bMota=Request("bMota")
	ZipDir =RootContent & "Data\xuly\"
	'Tinh so thu tu tiep theo cua vanban
	Set Post = Server.CreateObject("ActiveFile.Post")
	'On Error Resume Next
	Post.Upload ZipDir
	Path=post.FormInputs("UploadedFile")
		if Err.number=0 then
			Dodai=Len(Path)
			i=dodai
			Do while  i>0
				if mid(Path,i,1)="\" then
					Pos=i
					exit do
				end if
				i=i-1
			Loop
			if Pos then
				Filename=right(Path,dodai-pos)
			end if	
			'Tinh so thu tu tiep theo cua van ban
			sSQL="Select Sothutu from flownode_tentep where  Maflownode = '"& ClsFun.Giaima(Maflow) &"' order by sothutu"
			Set RecSTT=server.CreateObject("ADODB.Recordset")
			RecSTT.CursorType=3
			RecSTT.CacheSize=5
			RecSTT.Open sSQL,Conn
			if RecSTT.RecordCount then
				RecSTT.MoveLast
				STT=RecSTT("Sothutu")+1
			else
				STT=1
			end if
			Set ClsFile=server.CreateObject("Vinalines.ClsFile")
			bExten=ClsFile.GetExtensionFile(filename)
			if bExTen<>"" then
				f=ClsFun.Giaima(Maflow) & "S" & cstr(STT) & "." & bExten 
			else
				f=ClsFun.Giaima(Maflow) & "S" & cstr(STT)
			end if
			Set File=server.CreateObject("ActiveFile.File")
			'Doi ten file sau khi upload
			File.Name=ZipDir & "\" &  f
			if File.Exists() then
				File.Delete()
			end if		
			File.Name=ZipDir & "\" &  Filename
			File.Rename ZipDir & "\" & f
			set File=nothing
			sSQL="Insert into flownode_tentep(Maflownode,Sothutu,Tentep,mota) values('"& ClsFun.Giaima(Maflow) &"',"& STT &",'"& f &"','"& replace(bMota,"'","''") &"')"
			Conn.Execute sSQL		
			bdaxuly="xulyok"
			msg="ok"
		else
			msg="cancel"
		end if
	Conn.Close
	Set Conn=nothing
	Response.Redirect "attach.asp?Nguoitao="& Nguoitao &"&bMaRoot="& bMaRoot &"&Maflow="& Maflow &"&Msg="& msg &"&IDFlow="& IDFlow &"&bdaxuly="& bdaxuly &"&yeucau="& yeucau &"&Filename="& Filename &"&UName="& UName &"&MaCB="& MaCB &"&Tentep="& Tentep &"&Hanxuly="& Hanxuly &"&bDatao="& bDatao &"&Backform="& Backform
	set ClsFun=nothing
%>